<style lang="less" scoped>
.cardiovascular-program {
  width: 100%;
  height: 100%;
  /deep/.el-table__inner-wrapper {
    height: 100% !important;
  }
  .fixed-box {
    position: fixed;
    width: 300px;
    height: 120px;
    bottom: 150px;
    z-index: 999;
    background-color: #fff;
    right: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 10px 10px 10px #ccc;
    border: 1px solid #eee;
    border-radius: 4px;
    .box-close {
      position: absolute;
      top: 10px;
      right: 10px;
      color: #666;
      cursor: pointer;
    }
    .box-title {
      font-size: 20px;
      line-height: 30px;
    }
    .box-num {
      font-size: 16px;
      line-height: 30px;
      span {
        font-size: 20px;
        color: #337ecc;
      }
    }
  }
  .pagination-css {
    padding: 5px;
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    justify-content: right;
    margin-top: 5px;
  }
}
</style>

<template>
  <div class="cardiovascular-program">
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline form-css"
    >
      <el-form-item label="关键字：">
        <el-input
          v-model="formInline.keyword"
          placeholder="请输入条码、姓名、设备名称"
        />
      </el-form-item>
      <el-form-item label="检查时间：">
        <el-date-picker
          v-model="formInline.inspectionTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD HH:mm:ss"
          style="width: 300px"
        />
      </el-form-item>
      <el-form-item label="上传时间：">
        <el-date-picker
          v-model="formInline.uploadTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD HH:mm:ss"
          style="width: 300px"
        />
      </el-form-item>
      <el-form-item label="项目点名称：">
        <el-input v-model="formInline.projectName" placeholder="" />
      </el-form-item>
      <el-form-item label="报告状态：">
        <el-select v-model="formInline.reportStatus" placeholder="">
          <el-option
            v-for="item in statusList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="search"
          ><el-icon style="margin-right: 6px"><Search /></el-icon>
          搜索</el-button
        >
        <el-button @click="reset"
          ><el-icon style="margin-right: 6px"><Refresh /></el-icon>
          重置</el-button
        >
        <!-- <el-button type="primary"><el-icon><Document /></el-icon>导出</el-button> -->
      </el-form-item>
    </el-form>
    <div class="filter-column">
      <el-popover
        placement="bottom"
        title="筛选条件"
        :width="150"
        trigger="click"
      >
        <el-checkbox-group v-model="filtrateList" @change="changeBox">
          <el-checkbox label="t_sn">条码</el-checkbox>
          <el-checkbox label="insname">项目点名称</el-checkbox>
          <el-checkbox label="name">姓名</el-checkbox>
          <el-checkbox label="sex">性别</el-checkbox>
          <el-checkbox label="age">年龄</el-checkbox>
          <el-checkbox label="devname">设备名称</el-checkbox>
          <el-checkbox label="auditstatus">报告状态</el-checkbox>
          <el-checkbox label="checkTime">检查时间</el-checkbox>
          <el-checkbox label="docname">检查医师</el-checkbox>
          <el-checkbox label="uploadTime">上传时间</el-checkbox>
          <el-checkbox label="devid">设备SN</el-checkbox>
        </el-checkbox-group>
        <template #reference>
          <el-button type="text"
            ><div class="shaixuan">
              <img src="@/images/shaixuan.png" alt="" /> 筛选列
            </div></el-button
          >
        </template>
      </el-popover>
    </div>
    <el-table
      v-loading="tableLoading"
      :data="tableData"
      :header-cell-style="{ backgroundColor: '#EEF6FF' }"
      border
      height="calc(100% - 207px)"
      style="width: 100%; padding: 10px"
    >
      <el-table-column type="index" width="50" align="center" />
      <el-table-column
        v-if="filtrateList.includes('t_sn')"
        prop="t_sn"
        min-width="120px"
        label="条码"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('insname')"
        prop="insname"
        min-width="120px"
        label="项目点名称"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('name')"
        prop="name"
        min-width="84px"
        label="姓名"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('sex')"
        prop="sex"
        min-width="84px"
        label="性别"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('age')"
        prop="age"
        min-width="84px"
        label="年龄"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('devname')"
        prop="devname"
        min-width="120px"
        label="设备名称"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('auditstatus')"
        prop="auditstatus"
        min-width="84px"
        label="报告状态"
        align="center"
      >
        <template #default="{ row }">
          <span>{{
            row.auditstatus == 0
              ? "待审核"
              : row.auditstatus == 1
              ? "审核中"
              : row.auditstatus == 2
              ? "退回重审"
              : row.auditstatus == 10
              ? "已审核"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="filtrateList.includes('checkTime')"
        prop="checkTime"
        min-width="120px"
        label="检查时间"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('docname')"
        prop="docname"
        min-width="100px"
        label="检查医师"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('uploadTime')"
        prop="uploadTime"
        min-width="120px"
        label="上传时间"
        align="center"
      />
      <el-table-column
        v-if="filtrateList.includes('devid')"
        prop="devid"
        min-width="120px"
        label="设备SN"
        align="center"
      />
    </el-table>
    <div v-if="showBox" class="fixed-box">
      <div class="box-close" @click="showBox = false">X</div>
      <div class="box-title">本期审核次数剩余</div>
      <div class="box-num">
        <span>{{ pageList.total }}</span
        >次
      </div>
    </div>
    <el-pagination
      v-model:current-page="pageList.current"
      v-model:page-size="pageList.size"
      :page-sizes="[20, 40, 60, 80]"
      small="small"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageList.total"
      class="pagination-css"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { getUltraCardioList } from "@/apis/reportList";
import format from "@/utils/format";
export default {
  data() {
    return {
      showBox: true,
      tableLoading: false,
      filtrateList: [
        "t_sn",
        "devid",
        "devname",
        "name",
        "sex",
        "age",
        "checkTime",
        "insname",
        "docname",
        "uploadTime",
        "auditstatus",
      ],
      formInline: {
        keyword: "",
        inspectionTime: [],
        uploadTime: [],
        projectName: "",
        reportStatus: "",
      },
      tableData: [],
      pageList: {
        current: 1,
        size: 20,
        total: 0,
      },
      statusList: [
        {
          label: "待审核",
          value: 0,
        },
        {
          label: "审核中",
          value: 1,
        },
        {
          label: "退回重审",
          value: 2,
        },
        {
          label: "已审核",
          value: 10,
        },
      ],
    };
  },
  mounted() {
    let carCerebrovascularProjectPoint = localStorage.getItem(
      "carCerebrovascularProjectPoint"
    );
    if (carCerebrovascularProjectPoint) {
      this.filtrateList = JSON.parse(carCerebrovascularProjectPoint);
    }
    this.init();
    this.saveCookie();
  },
  methods: {
    saveCookie() {
      let carCerebrovascularProjectPoint = JSON.stringify(this.filtrateList);
      localStorage.setItem(
        "carCerebrovascularProjectPoint",
        carCerebrovascularProjectPoint
      );
    },
    changeBox() {
      let carCerebrovascularProjectPoint = JSON.stringify(this.filtrateList);
      localStorage.setItem(
        "carCerebrovascularProjectPoint",
        carCerebrovascularProjectPoint
      );
    },
    init() {
      this.getTableData();
    },
    getTableData() {
      this.tableData = [];
      this.tableLoading = true;
      getUltraCardioList({
        page: this.pageList.current, // 当前页
        size: this.pageList.size, // 每页size
        uname: this.$store.getters.name, // 登录用户
        insname: this.$store.getters.insname, //用户机构名
        keyword: this.formInline.keyword ? this.formInline.keyword : "", // 关键字
        inspectionStime: this.formInline.inspectionTime
          ? this.formInline.inspectionTime[0]
            ? this.formInline.inspectionTime[0]
            : ""
          : "", // 检查开始时间
        inspectionEtime: this.formInline.inspectionTime
          ? this.formInline.inspectionTime[1]
            ? this.formInline.inspectionTime[1]
            : ""
          : "", // 检查结束时间
        uploadStime: this.formInline.uploadTime
          ? this.formInline.uploadTime[0]
            ? this.formInline.uploadTime[0]
            : ""
          : "", //上传开始时间
        uploadEtime: this.formInline.uploadTime
          ? this.formInline.uploadTime[1]
            ? this.formInline.uploadTime[1]
            : ""
          : "", //上传结束时间
        reportStime: this.formInline.reportTime
          ? this.formInline.reportTime[0]
            ? this.formInline.reportTime[0]
            : ""
          : "", //报告开始时间
        reportEtime: this.formInline.reportTime
          ? this.formInline.reportTime[1]
            ? this.formInline.reportTime[1]
            : ""
          : "", //报告结束时间
        projectName: this.formInline.projectName
          ? this.formInline.projectName
          : "", //项目点名称
        auditorName: this.formInline.auditorName
          ? this.formInline.auditorName
          : "", //审核机构名称
        auditorDoctor: this.formInline.auditorDoctor
          ? this.formInline.auditorDoctor
          : "", //审核医师
        reportStatus: this.formInline.reportStatus
          ? this.formInline.reportStatus
          : "", //报告状态
        project: "脑卒中",
      }).then((res) => {
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            res.data.forEach((el) => {
              el.checkTime = format(el.checkTime * 1000, "YYYY-MM-DD HH:mm:ss");
              el.uploadTime = format(
                el.uploadTime * 1000,
                "YYYY-MM-DD HH:mm:ss"
              );
            });
            this.tableData = res.data;
            this.pageList.total = res.size;
          }
          this.tableLoading = false;
        }
      });
    },
    // 搜索
    search() {
      this.pageList.current = 1;
      this.getTableData();
    },
    // 重置
    reset() {
      this.formInline.keyword = "";
      this.formInline.inspectionTime = [];
      this.formInline.uploadTime = [];
      this.formInline.reportTime = [];
      this.formInline.projectName = "";
      this.formInline.reportStatus = "";
      this.pageList.current = 1;
      this.pageList.size = 20;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.pageList.current = 1;
      this.pageList.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.pageList.current = val;
      this.getTableData();
    },
  },
};
</script>
